﻿package server;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.SQLException;
import java.util.Date;

public class ResWaiter extends UnicastRemoteObject implements ResWaiterInterface  {
	
	private int WaiterNumber;
	private ResTable table;
	static java.util.ArrayList<ResWaiter> busyWaiter= new java.util.ArrayList<ResWaiter>(); 

	public ResWaiter(int a) throws RemoteException {
		
		super();
		// TODO Auto-generated constructor stub
		WaiterNumber=a;
	}

	//public ResWaiter(int jN) {
	//	super(jN);
		// TODO Auto-generated constructor stub
	//}



	/**
	 * @param args
	 */
	
	public void setStaffNumber(int n)throws RemoteException{
		WaiterNumber=n;
	}
	public double getSalary(int a)throws RemoteException{
		double b=1000;    //b为数据库里调出工资信息
		return b;
	}
	
	public int searchEmptyTable(int a)throws RemoteException{

		int b=0;
		if(a<=4)
			b=1;
		else if(a>4&&a<13)
			b=2;
		else
			b=3;
		ResTable table=new ResTable();
		int number=table.getTableNumber(b);
		if(number!=0)
			table.setTableState(number,1);
		return number;
	}
	public int getDescription(int a){
		return a;
		
	}

	
	public double TolHp(int []a) throws RemoteException{
		
		double sum=0.0;
		ResMenuList menuList = new ResMenuList();
		for(int dishNum:a){
			sum+=menuList.getHp(dishNum);
		}
		return sum;
	}


	public double TolAmount(int []a) throws RemoteException{
		double sum=0.0;
		ResMenuList menuList = new ResMenuList();
		for(int dishNum:a){
			sum+=menuList.getPrice(dishNum);
		}
		
		return sum;
	}
	
	public int RecordBook(int workNum,int pNum,String name,String phone,Date date)throws RemoteException{
		ResBookInfo book=new ResBookInfo();
		int t=book.addResOrder(workNum,pNum,name,phone,date);
		return t;
	}
	
	public int searchWaiter()throws RemoteException{
		int number=0;
		ResStaffList list;
		try {
			list = new ResStaffList();
	
		
		number=list.getFirstStaff(1);
		ResWaiter waiter=new ResWaiter(number);
		
		while(ResWaiter.busyWaiter.contains(waiter)){	
	
		
			number=list.getNextStaffNum(1, number);
				waiter.setStaffNumber(number);

		}	
		ResWaiter.busyWaiter.add(waiter);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
			return number;
	}
	
	
	public void addTable(int size) throws RemoteException
	{
		table=new ResTable();
		int t=table.getTableListSize();
		try {
			table.addTableNumber(t+1,size);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/*public static void main(String[] args) {
		// TODO Auto-generated method stub

	}*/



}
